/*
 * File.h
 *
 *  Created on: 22/06/2014
 *      Author: Vitor
 */

#ifndef FILE_H_
#define FILE_H_

#include <string>
#include <vector>
#include <stdio.h>

class File {
private:
	FILE* fp;
	bool file_exists;

public:
	File(std::string file_name, std::string mode);
	virtual ~File();

	bool exists() {
		return this->file_exists;
	}
	std::vector<char> read_file_contents();

	void binary_write(const std::vector<char>& data);
	template<typename T> void binary_write(T data) {
		fwrite(&data, sizeof(T), 1, fp);
	}

	std::vector<char> binary_read(size_t count);
	template<typename T> T binary_read() {
		T read_value;
		fread(&read_value, sizeof(T), 1, fp);
		return read_value;
	}
};

#endif /* FILE_H_ */
